<template>
    <div style="padding: 20px;box-sizing: border-box;background:#fff">
      <el-input
        placeholder="请输入版本号"
        v-model="searchContent"
        clearable style="width: 300px;margin-bottom: 16px;"
      >
      </el-input>
      <div>
        <el-button type="primary" v-for="(item,index) in typeIdList" @click="exportExcel(item)">{{ item.name }}</el-button>
      </div>
    </div>
  </template>
  
  <script>
  import { buildUsingPOST, handleDownloadUsingPOST, handleYBDownload } from '@/api/mgmt/insurance/down.js'
  import { ybPost } from '@/utils/ybRequest'
  
  export default {
    data() {
      return {
        searchContent: '',
        typeIdList: [{ id: 1, name: '疾病与诊断目录' }, { id: 2, name: '门诊慢特病种目录' }, { id: 3, name: '按病种付费病种目录' }],
        typeId: 1
      }
    },
    mounted() {
  
    },
    methods: {
      exportExcel(item) {
        this.typeId = item.id
        this.getData()
      },
      getData() {
        switch (this.typeId) {
          case 1:
            buildUsingPOST({ ver: this.searchContent }, 1307).then(res => {
              const { astr_jysr } = res.data
              ybPost(astr_jysr).then(res => {
                if (res.infcode == -1) {
                  this.$message.error(res.err_msg)
                  return
                }
                handleYBDownload({ fileQuryNo: res.output.file_qury_no }).then(res => {
                  const { astr_jysr } = res.data
                  ybPost(astr_jysr, 1).then(res => {
                    // 创建下载链接
                    /*  let fileName = 'medical_report.zip'
                     const blob = new Blob([res], { type: 'application/zip' })
                     const downloadUrl = window.URL.createObjectURL(blob)
                     console.log(downloadUrl)
                     const link = document.createElement('a')
                     link.href = downloadUrl
                     link.download = fileName
                     document.body.appendChild(link)
  
                     // 触发下载
                     link.click()
                     window.URL.revokeObjectURL(downloadUrl)
                     document.body.removeChild(link) */
                    const fileBlob = new Blob([res], { type: 'application/zip' })
  
                    // 创建下载链接
                    const downloadUrl = URL.createObjectURL(fileBlob)
                    const link = document.createElement('a')
  
                    // 使用截图中的文件名作为下载文件名
                    const fileName = '疾病与诊断目录.zip'
  
                    link.href = downloadUrl
                    link.download = fileName
                    link.style.display = 'none'
                    document.body.appendChild(link)
  
                    // 触发下载
                    link.click()
  
                    // 清理资源
                    setTimeout(() => {
                      URL.revokeObjectURL(downloadUrl)
                      document.body.removeChild(link)
                    }, 100)
                  })
                }).catch(err => {
                  this.$message.error(err.message)
                })
                // handleDownloadUsingPOST(res).then(res => {
                //   this.$message.success('疾病与诊断目录下载完成！')
                // }).catch(err => {
                //   this.$message.error(err.message)
                // })
              })
            })
            break
          case 2:
            //1./item/1309/build
            buildUsingPOST({ ver: this.searchContent }, 1309).then(res => {
              const { astr_jysr } = res.data
              ybPost(astr_jysr).then(res => {
                if (res.infcode == -1) {
                  this.$message.error(res.err_msg)
                  return
                }
                handleYBDownload({ fileQuryNo: res.output.file_qury_no }).then(res => {
                  const { astr_jysr } = res.data
                  ybPost(astr_jysr, 1).then(res => {
                    // 创建下载链接
                    /*  let fileName = 'medical_report.zip'
                     const blob = new Blob([res], { type: 'application/zip' })
                     const downloadUrl = window.URL.createObjectURL(blob)
                     console.log(downloadUrl)
                     const link = document.createElement('a')
                     link.href = downloadUrl
                     link.download = fileName
                     document.body.appendChild(link)
  
                     // 触发下载
                     link.click()
                     window.URL.revokeObjectURL(downloadUrl)
                     document.body.removeChild(link) */
                    const fileBlob = new Blob([res], { type: 'application/zip' })
  
                    // 创建下载链接
                    const downloadUrl = URL.createObjectURL(fileBlob)
                    const link = document.createElement('a')
  
                    // 使用截图中的文件名作为下载文件名
                    const fileName = '门诊慢特病种目录.zip'
  
                    link.href = downloadUrl
                    link.download = fileName
                    link.style.display = 'none'
                    document.body.appendChild(link)
  
                    // 触发下载
                    link.click()
  
                    // 清理资源
                    setTimeout(() => {
                      URL.revokeObjectURL(downloadUrl)
                      document.body.removeChild(link)
                    }, 100)
                  })
                }).catch(err => {
                  this.$message.error(err.message)
                })
                /* handleDownloadUsingPOST(res).then(res => {
                  this.$message.success('门诊慢特病种目录下载完成！')
                }).catch(err => {
                  this.$message.error(err.message)
                }) */
              })
            })
            break
          case 3:
            //1./item/1310/build
            buildUsingPOST({ ver: this.searchContent }, 1310).then(res => {
              const { astr_jysr } = res.data
              ybPost(astr_jysr).then(res => {
                if (res.infcode == -1) {
                  this.$message.error(res.err_msg)
                  return
                }
                handleYBDownload({ fileQuryNo: res.output.file_qury_no }).then(res => {
                  const { astr_jysr } = res.data
                  ybPost(astr_jysr, 1).then(res => {
                    // 创建下载链接
                    /*  let fileName = 'medical_report.zip'
                     const blob = new Blob([res], { type: 'application/zip' })
                     const downloadUrl = window.URL.createObjectURL(blob)
                     console.log(downloadUrl)
                     const link = document.createElement('a')
                     link.href = downloadUrl
                     link.download = fileName
                     document.body.appendChild(link)
  
                     // 触发下载
                     link.click()
                     window.URL.revokeObjectURL(downloadUrl)
                     document.body.removeChild(link) */
                    const fileBlob = new Blob([res], { type: 'application/zip' })
  
                    // 创建下载链接
                    const downloadUrl = URL.createObjectURL(fileBlob)
                    const link = document.createElement('a')
  
                    // 使用截图中的文件名作为下载文件名
                    const fileName = '按病种付费病种目录.zip'
  
                    link.href = downloadUrl
                    link.download = fileName
                    link.style.display = 'none'
                    document.body.appendChild(link)
  
                    // 触发下载
                    link.click()
  
                    // 清理资源
                    setTimeout(() => {
                      URL.revokeObjectURL(downloadUrl)
                      document.body.removeChild(link)
                    }, 100)
                  })
                }).catch(err => {
                  this.$message.error(err.message)
                })
                // handleDownloadUsingPOST(res).then(res => {
                //   this.$message.success('按病种付费病种目录下载完成！')
                // }).catch(err => {
                //   this.$message.error(err.message)
                // })
              })
            })
            break
          default:
            break
        }
      }
    }
  }
  </script>
  
  <style>
  
  </style>
  